package com.itany.cloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        // 参数一:当前路由的id,具有唯一性
        // 参数二:使用lambda表达式配置路由
        // path方法:用于配置请求,对进入Gateway的请求进行过滤
            // 当满足该格式的请求才会进入该路由,支持通配符
        // uri:请求转发的地址
        return routes.route("users_route", r -> r.path("/users/**").uri("http://127.0.0.1:8001")).build();
    }

    @Bean
    public RouteLocator routeLocator2(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        return routes.route("news_route", r -> r.path("/guonei/**").uri("https://news.baidu.com/guonei")).build();
    }

}
